<template>
    <div class="call-server-wrapper">
        <div class="container">
            <div class="item"
                 @click="callServer(item.name)"
                 v-for="(item, index) in serviceInfo " :key="index">
                <div class="item-item">
                    <img src="../components/common/img/tea.svg" v-if="item.name == '倒茶'"/>
                    <img src="../components/common/img/soup.svg" v-else-if="item.name == '加汤'"/>
                    <img src="../components/common/img/dish.svg" v-else-if="item.name == '加菜'"/>
                    <img src="../components/common/img/alcohol.svg" v-else-if="item.name == '酒水饮料'"/>
                    <img src="../components/common/img/pay.svg" v-else-if="item.name == '结账'"/>
                    <img src="../components/common/img/tissuepaper.svg" v-else-if="item.name == '纸巾'"/>
                    <!--<img src="../components/common/img/bell.svg" v-else/>-->
                    <span>{{item.name}}</span>
                </div>
            </div>
        </div>

        <div class="bottom-btn" @click="callServer('喊过来再说')">喊过来再说</div>
    </div>
</template>
<script>
    import axios from '../plugins/axios';
    import {MessageBox} from 'mint-ui';
    export default {
        async asyncData ({res, req, error}) {
            let response = {};
            let userInfo = res.locals.userInfo;
            let token = res.locals.token;
            let tableInfo = req.query;
            try {
                response = await axios.get('/api/h5/customer/store-service', {
                    params: {
                        store_id: tableInfo.store,
                        token
                    }
                });
                response = response.data || {};
            } catch (e) {
                error({});
            }
            return {
                //serviceInfo: response.data,
                serviceInfo: [{
                        name: '倒茶'
                    },
                    {
                        name: '加汤'
                    },
                    {
                        name: '加菜'
                    },
                    {
                        name: '酒水饮料'
                    },
                    {
                        name: '结账'
                    },
                    {
                        name: '纸巾'
                    }],
                userInfo,
                token,
                tableInfo,
            }
        },
        head () {
            return {
                title: '呼叫服务'
            }
        },
        methods: {
            callServer(name){
                let tableInfo = this.tableInfo;
                let store = tableInfo.store;
                let order = tableInfo.order;
                let table = tableInfo.table;
                axios.post('/api/h5/customer/store-service', {
                    store_id: store,
                    service_name: name,
                    order: tableInfo.order,
                    token: this.token
                }).then(res => {
                    if (res.data.error == 0) {
                        MessageBox.alert('系统系统', '已向服务员呼叫服务成功').then(() => {
                            window.location.href = `/dinner?store=${store}&table=${table}&order=${order}`
                        });
                    } else {
                        MessageBox('系统系统', res.data.desc);
                    }
                }).catch(e => {
                    MessageBox('系统系统', '呼叫失败');
                })
            }
        }
    }
</script>
<style lang="less">
    .call-server-wrapper {
        min-height: 100vh;
        background: #eee;
        display: flex;
        justify-content: center;
        .container {
            font-size: 16px;
            display: flex;
            justify-content: space-between;
            flex-wrap: wrap;
            height: calc( 100vh - 65px);
            overflow: scroll;
            padding: 20px;
            -webkit-overflow-scrolling: touch;
            .item {
                width: 48%;
                margin-bottom: 20px;
                display: flex;
                justify-content: center;
                align-items: center;
                .item-item {
                    display: flex;
                    text-align: center;
                    flex-direction: column;
                    width: 160px;
                    height: 160px;
                    background: #FFFFFF;
                    box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.10);
                    border-radius: 8px;
                    align-items: center;
                    font-size: 18px;
                    letter-spacing: 0.22px;
                    img {
                        width: 120px;
                        height: 120px;
                    }
                }
            }
        }
        .bottom-btn {
            position: absolute;
            border-bottom: 0;
            background: #000000;
            box-shadow: 0 -2px 10px 0 rgba(0, 0, 0, 0.10);
            height: 65px;
            line-height: 65px;
            font-size: 18px;
            color: #FFFFFF;
            text-align: center;
            bottom: 0;
            left: 0;
            right: 0;
        }
    }
</style>